<template>
  <div id="patientDetails">
    <header>
      <span @click="goBack()">返回</span>
      <div>患者详情</div>
    </header>
    <section>
      <ul>
        <li>
          <img src="../../../image/bg_touxiang@2x.png" width='43' height='43' alt="">
          <h3>{{infoObj.name}}</h3>
          <i>{{infoObj.age}}岁</i>
          <i>{{infoObj.sex}}</i>
          <router-link :to="{name: 'addPatient',query: {status: 'edit',id: infoObj.id}}">编辑</router-link>
        </li>
        <li>
          <div>电话号码: {{infoObj.tele}}</div>
        </li>
      </ul>
      <div class="content">
        <label @change='select'>
          <img src="../../../image/icon_reservation_record@2x.png" width='66' height="66" alt="">
          <input type="radio" v-model="type" value='0'>
          <i>预约记录</i>
        </label>
        <label @change='select'>
          <img src="../../../image/icon_medical_records@2x.png" width='66' height="66" alt="">
          <input type="radio" v-model="type" value='1'>
          <i>病历记录</i>
        </label>
      </div>
    </section>
    <footer>
      <a class='sms' :href="'sms:'+ infoObj.tele">发短信</a>
      <a class='tel' :href="'tel:' + infoObj.tele">打电话</a>
    </footer>
  </div>
</template>
<script>
  import {
    Loadmore
  } from 'mint-ui';
  export default {
    data() {
      return {
        type: '',
        pid: '',
        infoObj: {},



        list: [],
        doctorid: '', //医生id
        pid: '', //患者id
        sentPage: {
          page: 1,
          rows: "10"
        }, //接口入参
        totalNum: 0, //总数据条数
        allLoaded: false, //分页数据是否已经加载完毕
      }
    },

    components: {
      Loadmore,
    },
    filters: {
      getDay: function (val) { //返回星期几
        var d = new Date(val);
        var weekday = new Array(7)
        weekday[0] = "星期天"
        weekday[1] = "星期一"
        weekday[2] = "星期二"
        weekday[3] = "星期三"
        weekday[4] = "星期四"
        weekday[5] = "星期五"
        weekday[6] = "星期六"
        return weekday[d.getDay()]
      }
    },


    methods: {

      //   goBack() {
      //         // this.$router.back();

      //         // this.$router.push({name:'appointmentTime',query: {user:'doctor'}});           
      //         this.$router.push({name:'patientDetails',query: {pid:this.pid}});           
      //     },
      // 获取预约患者列表
      getList(params) {
        this.doctorid = localStorage.getItem("loginMobile");
        this.pid = this.$route.query.pid;
        this.$api.post(this.$api.baseURLSchool, "selecttype_view/appointment/0?pid=" + this.pid + "&doctorid=" + this.doctorid,
          params, r => {
            console.log(r);
            this.totalNum = r.data.records; //总数据
            if (this.sentPage.page == 1) {
              this.list = r.data.rows;
            } else {
              this.list = this.list.concat(r.data.rows);
            }
            if (r.data.rows.length == 0 && this.sentPage.page > 1) {
              this.$utils._toast("暂无更多数据");
            }
            if (this.totalNum == this.list.length) {
              this.allLoaded = true;
            }

          }, err => {
            console.log(err);
          })
      },
      //新建预约
      addNewAppointment() {
        this.$router.push({
          name: 'addNewAppointment',
          query: {
            from: "reservation_record",
            pid: this.pid,
            status: 'add'
          }
        });
        // if(localStorage.getItem('name')=='"clinic"'){
        //     this.$router.push({name:'addNewAppointment1',
        //     query: {from: "reservation_record",pid: this.pid}});
        // }else if(localStorage.getItem('name')=='"doctor"'){

        // }
      },
      //上拉加载下一页
      loadBottom() {
        (this.sentPage.page) ++;
        setTimeout(() => {
          this.getList(this.sentPage);
        }, 20);
        if (this.totalNum == this.list.length) {
          this.allLoaded = true;
        }
        this.$refs.loadmore.onBottomLoaded();
      },


      toNext(id) {
        if (this.$route.query.name == 'order') {
          this.$router.push({
            name: 'clinicDetail',
            query: {
              pid: this.pid,
              blid: id,
              user: 'doctor',
              id: this.doctorid
            }
          });
        } else {
          this.$router.push({
            name: 'reservation_details',
            query: {
              pid: this.pid,
              id: id
            }
          });
        }

      },
      goBack() {
        // this.$router.push({name:'selectpatient',query: {from: 'patients'}})
        this.$router.push({
          name: 'allpatient',
          query: {
            from: 'patients',
            user:'clinic'
          }
        })
      },
      //选择是预约记录0还是病例记录1
      select() {
        if (this.type == '0') {
          if (this.$route.query.name == 'order') {
            this.$router.push({
              name: 'reservation_record',
              query: {
                pid: this.pid,
                name: 'order'
              }
            });
          } else {

            this.$router.push({
              name: 'reservation_record',
              query: {
                pid: this.pid
              }
            });
          }


        } else if (this.type == '1') {
          this.$router.push({
            name: 'medical_records1',
            query: {
              pid: this.pid
            }
          });
        }
        console.log(this.type);
      },
      //获取患者详情
      getDetailsData() {
        this.pid = this.$route.query.pid;
        this.$api.get(this.$api.baseURLSchool, "select_cid/patient/" + this.pid, {}, r => {
          console.log(r);
          if (r.data.ret == 1) {
            this.infoObj = r.data.info;
          }
        }, err => {
          console.log(err);
        })
      },
      //保存
      save() {

      },
    },
    created() {
      this.getDetailsData();

      this.getList(this.sentPage);
    }
  }

</script>
<style lang="scss" scoped>
  .mc {
    padding-top: 115px;

    img {
      display: block;
      margin: 0 auto;
    }

    p {
      padding-top: 10px;
      text-align: center;
      font-size: 17px;
      color: rgba(51, 51, 51, 1);
    }
  }

</style>
